package com.hanson.common.handler;

import com.hanson.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public BusinessException handleException(Exception e) {
        log.error("系统内部异常，异常信息", e);
        return new BusinessException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "系统内部异常");
    }

    @ExceptionHandler(value = BusinessException.class)
    public BusinessException handleFebsException(BusinessException e) {
        log.error("系统错误", e);
        return new BusinessException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
    }
}
